<template>
  <div class="main" span="24">
       <div class="head"><img src="../../../static/images/banner1.jpg"></div>
     <!-- <p class="title">&nbsp;个人信息</p> -->
    <!-- <div class="info-box"> -->
     <div class="weui-cells__title">用户登录</div>
     <div class="weui-cells weui-cells_form">
       <!-- <div class="weui-cell">
         <div class="weui-cell__hd">
        <label class="weui-label">用户名</label>
       </div>
      <div class="weui-cell__bd">
      <input class="weui-input" placeholder="请输入用户名" v-model="userinfo.username"> 
      </div>
      </div>  -->
      <div class="weui-cell">
         <div class="weui-cell__hd">
        <label class="weui-label">手机号</label>
       </div>
      <div class="weui-cell__bd">
        <input class="weui-input" type="tel" placeholder="请输入手机号" v-model="userinfo.telphone">
      </div>
      <div class="weui-cell__ft">
        <button class="weui-vcode-btn" @click="getcode" :disabled="sendsuccess" id="showLoadingToast">{{vcode}}</button>
      </div>
      </div>
        <div class="weui-cell">
         <div class="weui-cell__hd">
        <label class="weui-label">验证码</label>
       </div>
      <div class="weui-cell__bd">
      <input class="weui-input" placeholder="请输入验证码" v-model="userinfo.verification"> 
      </div>
      </div> 
       <!-- <div class="weui-cell">
         <div class="weui-cell__hd">
        <label class="weui-label">企业名称</label>
       </div>
      <div class="weui-cell__bd">
      <input class="weui-input" placeholder="请输入企业名称"  v-model="userinfo.companyname">
      </div>
      </div> 
       <div class="weui-cell">
         <div class="weui-cell__hd">
        <label class="weui-label">密码</label>
       </div>
      <div class="weui-cell__bd">
      <input class="weui-input" placeholder="请输入密码" v-model="userinfo.password"> 
      </div>
      </div> 
       <div class="weui-cell">
         <div class="weui-cell__hd">
        <label class="weui-label">确认密码</label>
       </div>
      <div class="weui-cell__bd">
      <input class="weui-input" placeholder="请再输入一次密码" v-model="userinfo.passwordagain"> 
      </div>
      </div>  -->
    </div>
   
   <i-button  type="success" shape="circle" @click="handlelogin()">登录</i-button>
    
    <i-button  type="success" shape="circle" @click="handleregister()">注册</i-button>   
    
  </div> 
</template>

<script>
import card from '@/components/card'
import 'mpvue-weui/src/style/weui.css';
import mpSearchbar from 'mpvue-weui/src/searchbar'
import {postRequest} from '@/utils/http'
export default {
  data () {
    return {
      motto: 'Hello miniprograme',
      userInfo: {
        nickName: 'mpvue',
        avatarUrl: 'http://mpvue.com/assets/logo.png'
      },
      vcode:"获取验证码",
      sendsuccess : false,
        totalTime: 60,
      userinfo:{
        username: "",
        telphone: "",
        verification:'',
        companyname:"",
        password:"",
        passwordagain:""
      }
    }
  },

  components: {
    card,
    mpSearchbar
  },

  methods: {
      async  getcode() {
        let params ={
                'PHONE':this.userinfo.telphone,
                'TYPE':'1' 
      };
      const info =  await postRequest('/sendSMSCaptchaCode/v0',params);
      const result = info.UNI_BSS_BODY;
      console.log(result);
       if(result.RSP.CODE == '0000'){
      
         setInterval(()=>{
           this.sendsuccess = true ;
         this.totalTime --;
         this.vcode =  this.totalTime + 's后重新发送';
      if(this.totalTime == 0){
       this.totalTime = 60;
        this.sendsuccess = false ;
       return 
       }
   },1000)

   }
   else{
     consloe.log(result.RSP.MESSAGE)
   }
  },
  handleregister(){
    wx.navigateTo(
          {
            url: '../register/main'//跳转到一般页面
          })
     },
    // { wx.switchTab( //跳转到导航页
    //       {
    //         url: '../homepage/main'
    //       })
    // },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    },
    clickHandle (ev) {
      console.log('clickHandle:', ev)
      // throw {message: 'custom test'}
    },

 async handlelogin(){
     let params ={
                'PHONE':this.userinfo.telphone,
                'CAPTCHA_CODE':this.userinfo.verification,
                'FROM_CHANNEL':"BJWeChatZ8",
                'LOGIN_IP':'10.14.116.37'  
      };
      const info = await postRequest('/loginBySms/v0',params);
      const result = info.UNI_BSS_BODY;
      console.log(result);
      if(result.RSP.CODE == "0000"){
          let info = wx.setStorageSync('info', JSON.stringify(result.RSP.DATA));
          //  var that = this;
        
        wx.switchTab(
          {
            url: '../myinfo/main'
          })
      }
      else{
        console.log(result.RSP.MESSAGE)
      }

  },
  },
    onLoad: function(options) {
    let that = this;
    that.objStorge = wx.getStorageSync("info");
    console.log((that.objStorge == ""));
    that.companyName = that.objStorge.companyName||"";
    that.companyArea = that.objStorge.companyArea||"";
    that.companyLicNum = that.objStorge.companyLicNum||"";
    that.userName = that.objStorge.userName||"";
    that.userPhone = that.objStorge.userPhone||"";
    that.userLicNum = that.objStorge.userLicNum||"";
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style lang="scss" scoped>
  .main{
    font-size: 20px;
        background-color: #ededed;
    p{
      font-size: 30px;
    }
  }
  .info-box{
    border:1px solid #000;
    border-radius: 8px;
    margin:10px 10px 30px 10px ;
    padding:10px;
  }
  .line{
    line-height:3em;

  }
  .title{
    position:relative;
    top:1.2em;
    left:1em;
    font-size:20px !important;;
    width:4.5em;
    background-color:#fff;
  }
  .weui-label{
    display: block;
    width: 6.5em;
    word-wrap: break-word;
    word-break: break-all;
  }
  .head {
  img {
    width: 100%;
    height: 100px;
  }
}
</style>
